/**
 * 
 */
package uniandes.dermatologia.training.activities;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import uniandes.dermatologia.R;
import uniandes.dermatologia.models.PhysicalExamination;
import uniandes.dermatologia.models.PhysicalExamination.Border;
import uniandes.dermatologia.singleton.DermatologiaUniandesApp;
import uniandes.dermatologia.training.CaseLogic;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioButton;

/**
 * @author Julio
 *
 */
public class BorderCaseActivity extends Activity {
	
	@Override
	// public View onCreateView( LayoutInflater inflater, ViewGroup container,
	// Bundle savedInstanceState )
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_border);

		getActionBar().setDisplayHomeAsUpEnabled(false);
		
		RadioButton radioPoorlyDemarcatedBorder = (RadioButton)findViewById(R.id.radioPoorlyDemarcatedBorder);
		radioPoorlyDemarcatedBorder.setEnabled(false);
		RadioButton radioWellDemarcatedBorder = (RadioButton)findViewById(R.id.radioWellDemarcatedBorder);
		radioWellDemarcatedBorder.setEnabled(false);
		
		

		DatePicker startDatePicker = (DatePicker) findViewById(R.id.datePickerStart);
		startDatePicker.setEnabled(false);
		
		DermatologiaUniandesApp app = (DermatologiaUniandesApp)getApplication();
		CaseLogic caseLogic = app.getCurrentCaseLogic();
		PhysicalExamination examination = caseLogic.getExamination();
		
		Border border = examination.getBorder();
		
		switch (border) {
		case well_demarcated:
			radioWellDemarcatedBorder.setChecked(true);
			break;
		case poorly_demarcated:
			radioPoorlyDemarcatedBorder.setChecked(true);
			break;

		default:
			break;
		}
		
		Date startDate = examination.getStartDate();
		
		Calendar calendar = new GregorianCalendar();
		
		calendar.setTime(startDate);
		
		int year = calendar.get(Calendar.YEAR);
		
		int month = calendar.get(Calendar.MONTH);
		
		int day = calendar.get(Calendar.DAY_OF_MONTH);
		
		startDatePicker.updateDate(year, month, day);

		Button btnBack = (Button) findViewById(R.id.btnBackBorder);
		Button btnNext = (Button) findViewById(R.id.btnNextBorder);

		Typeface font = Typeface.createFromAsset(getAssets(),
				"fonts/Roboto-Light.ttf");

		btnBack.setTypeface(font);
		btnNext.setTypeface(font);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.border, menu);
		return false;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	public void onClickNext(View v) {

		Intent intent = new Intent(this, SymptomsCaseActivity.class);
		startActivity(intent);
	}

	public void onClickBack(View v) {
		finish();
	}
	
	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onPause()
	 */
	@Override
	protected void onPause() {
		super.onPause();
		DermatologiaUniandesApp app = (DermatologiaUniandesApp)getApplication();
		app.stopTimer();
	}
	
	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		DermatologiaUniandesApp app = (DermatologiaUniandesApp)getApplication();
		app.startTimer();
	}

}
